import {Global, Module} from '@nestjs/common';
import {User} from "./user.entity";
import {Photo} from "./photo.entity";
import {TypeOrmModule} from '@nestjs/typeorm';
import {MongoModule} from "../../common/db/mongo/mongo.module";
@Global()
@Module({
    imports:[
        // 多个数据库链接
        MongoModule.forRoot({
            entities: [__dirname + '/entity/mongo/**/*.entity.ts'],
            name: 'testConnection',
            database: 'test'
        }),
        MongoModule.forRoot({
            entities: [__dirname + '/entity/mongo/**/*.entity.ts'],
            name: 'ucConnection',
            database: 'uc'
        }),
        // 加载数据库链接模块 todo 现在情况是 forRootAsync不能实现多个数据库，而forRoot可以
        // MongoModule.forRootAsync({
        //     entities: [__dirname + '/entity/mongo/**/*.entity.ts'],
        //     name: 'testConnection',
        //     database: 'test'
        // }),
        // MongoModule.forRootAsync({
        //     entities: [__dirname + '/entity/mongo/**/*.entity.ts'],
        //     name: 'ucConnection',
        //     database: 'uc'
        // }),
        // 声明表模块
        TypeOrmModule.forFeature([User],"ucConnection"), //加载数据库设计模块
        TypeOrmModule.forFeature([Photo],"testConnection"),
    ],
    exports: [
        TypeOrmModule.forFeature([User],"ucConnection"), //加载数据库设计模块
        TypeOrmModule.forFeature([Photo],"testConnection")
    ],
})
export class MongoEntityModule {}
